package com.hushao.lims.weblims.controller;

import com.hushao.lims.weblims.domain.EquipmentApply;
import com.hushao.lims.weblims.service.EquipmentApplyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author 930588706
 * @date 18/2/9
 */
@Controller
@RequestMapping("/equipmentApply")
public class EquipmentApplyController {

    @Autowired
    private EquipmentApplyService equipmentApplyService;

    /**
     * 模糊查看器材申请使用列表（分页）
     * @param equipmentName
     * @param state
     * @param async
     * @param pageable
     * @param model
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "查看器材申请使用列表(分页)")
    @PreAuthorize("hasAuthority('ROLE_主管')")
    @GetMapping
    public String listEquipmentApply(@RequestParam(value = "equipmentName",required = false,defaultValue = "") String equipmentName,
                                      @RequestParam(value = "state",required = false,defaultValue = "") String state,
                                      @RequestParam(value = "async",required = false) boolean async,
                                      Pageable pageable,
                                      Model model)throws Exception{
        Page<EquipmentApply> equipmentApplyPage=equipmentApplyService.listEquipmentApplyByNameLikeAndStateLike(equipmentName,state,pageable);
        List<EquipmentApply> equipmentApplies =equipmentApplyPage.getContent();
        model.addAttribute("page",equipmentApplyPage);
        model.addAttribute("equipmentApplies",equipmentApplies);
        return async==true?"/audit/equipmentApplies ::#mainContainerRepleace":"/audit/equipmentApplies";
    }
}
